package com.adingxiong.quickstart.util;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * @ClassName DateUtils
 * @Description  日期工具类
 * @Author xiongchao
 * @Date 2020/7/8 11:01
 **/
public class DateUtils {


    /**
     *  获取年度月份
     * @return
     */
    public static List<String> getMonths(){

        ArrayList<String> arrayList = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Calendar min = Calendar.getInstance();
        Calendar max = Calendar.getInstance();

        min.set(Calendar.MONTH,0);
        max.add(Calendar.MONTH,1);

        Calendar curr = min ;
        while(curr.before(max)){
            arrayList.add(sdf.format(curr.getTime()));
            curr.add(Calendar.MONTH,1);
        }
        return arrayList;
    }

    /**
     * 获取月度每日
     * @return
     */
    public static List<String> getDays(){
        ArrayList<String> arrayList = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar min = Calendar.getInstance();
        Calendar max = Calendar.getInstance();

        min.set(Calendar.DAY_OF_MONTH,1);
        max.add(Calendar.DAY_OF_MONTH,1);

        Calendar curr = min ;
        while(curr.before(max)){
            arrayList.add(sdf.format(curr.getTime()));
            curr.add(Calendar.DAY_OF_MONTH,1);
        }
        return arrayList;
    }


}
